package com.weapons.week0903_weapons.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.weapons.week0903_weapons.R;
import com.weapons.week0903_weapons.bean.RecommentBean;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Administrator on 2016/7/20.
 */
public class RecommendListAdapter extends RecyclerView.Adapter<RecommendListAdapter.ItemHoler> {
    private Context mContext ;
    private List<RecommentBean.ItemBean> mDatas;
    public RecommendListAdapter(Context context ,List<RecommentBean.ItemBean> datas){
        this.mContext=context;
        this.mDatas=datas;
    }
    @Override
    public ItemHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.recomment_item, null);
        ItemHoler  holer = new ItemHoler(view);
        return holer;
    }

    @Override
    public void onBindViewHolder(ItemHoler holder, int position) {
        Picasso.with(mContext).load(mDatas.get(position).getImage()).into(holder.iv_itemImage);
        holder.tv_title.setText(mDatas.get(position).getTitle());
        holder.tv_time.setText(mDatas.get(position).getPubDate());
        holder.tv_comment.setText(mDatas.get(position).getComments()+"评论");
    }

    @Override
    public int getItemCount() {
        return mDatas==null?0:mDatas.size();
    }

    class ItemHoler extends RecyclerView.ViewHolder {
        private ImageView iv_itemImage;
        private TextView tv_title,tv_time,tv_comment;
        public ItemHoler(View itemView) {
            super(itemView);
            iv_itemImage= (ImageView) itemView.findViewById(R.id.iv_itemImage);
            tv_comment= (TextView) itemView.findViewById(R.id.tv_comment);
            tv_time= (TextView) itemView.findViewById(R.id.tv_time);
            tv_title= (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
}
